package arrowandsphere;

import java.io.*;
import java.net.*;
import java.util.*;

public class Bean {
    Socket s;
    ObjectInputStream ois;
    ObjectOutputStream oos;

    public Bean() throws Exception {
        s = new Socket("localhost", 1234);
        ois = new ObjectInputStream(s.getInputStream());
        oos = new ObjectOutputStream(s.getOutputStream());
    }
    
    public int createSession(int numberOfPlayers) throws Exception {
        oos.writeObject(new CreateSession(numberOfPlayers));
        oos.flush();
        return 0;
    }
    
    public List<Session> readSessions() throws Exception {
        oos.writeObject(new ReadSessions());
        oos.flush();
        return (List<Session>)ois.readObject();
    }
    
    public Session readSession(int sessionId) throws Exception {
        oos.writeObject(new ReadSession(sessionId));
        oos.flush();
        return (Session)ois.readObject();
    }
    
    public void updateSession(int sessionId, Session session) throws Exception {
        oos.writeObject(new UpdateSession(sessionId, session));
        oos.flush();
    }
}